export const USER_KEY = 'users'
export const CURRENT_KEY = 'currentUser'

// 用户信息
export const getUsers = (): Record<string, string> =>
    JSON.parse(localStorage.getItem(USER_KEY) || '{}')

export const setUsers = (users: Record<string, string>) =>
    localStorage.setItem(USER_KEY, JSON.stringify(users))

export const setCurrent = (username: string) =>
    localStorage.setItem(CURRENT_KEY, username)

export const getCurrent = (): string | null =>
    localStorage.getItem(CURRENT_KEY)

export const clearCurrent = () =>
    localStorage.removeItem(CURRENT_KEY)

// 用户任务
export const getTasks = (username: string) =>
    JSON.parse(localStorage.getItem(`tasks_${username}`) || '[]')

export const setTasks = (username: string, tasks: any[]) =>
    localStorage.setItem(`tasks_${username}`, JSON.stringify(tasks))
